package com.block.common.encrypt.factory;

import com.block.common.encrypt.service.IEncryptTypeServcie;
import com.block.common.encrypt.enums.EncryptTypeEnum;
import com.block.common.encrypt.service.type.AesEncrpytService;
import com.block.common.encrypt.service.type.Md5EncrpytService;
import com.block.common.encrypt.service.type.RsaEncrpytService;
import com.block.common.encrypt.service.type.TokenEncrpytService;
import com.block.common.util.ApplicationContextUtil;

import java.util.HashMap;
import java.util.Map;

public class EncryptFactory {

    private static Map<String, Class<? extends IEncryptTypeServcie>> serviceMap = new HashMap<>();
    static {
        serviceMap.put(EncryptTypeEnum.RSA.getValue(), RsaEncrpytService.class);
        serviceMap.put(EncryptTypeEnum.AES.getValue(), AesEncrpytService.class);
        serviceMap.put(EncryptTypeEnum.TOKEN.getValue(), TokenEncrpytService.class);
        serviceMap.put(EncryptTypeEnum.MD5.getValue(), Md5EncrpytService.class);
    }

    public static IEncryptTypeServcie getService(String type){
        if (serviceMap.containsKey(type)){
            Class<? extends IEncryptTypeServcie> aClass = serviceMap.get(type);
            return ApplicationContextUtil.getBean(aClass);
        }
        return null;
    }
}
